package com.yunhe.day322.service.impl;

import com.github.pagehelper.PageHelper;
import com.yunhe.day322.dao.RoleDao;
import com.yunhe.day322.domain.Permission;
import com.yunhe.day322.domain.Role;
import com.yunhe.day322.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;
    @Override
    public List<Role> findAll(int page,int size) {
        PageHelper.startPage(page,size);

        return roleDao.findAll();
    }

    @Override
    public void save(Role role) {
        roleDao.save(role);
    }
    /**
     * 角色详情
     * @param id
     * @return
     */
    @Override
    public Role findById(int id) {
        Role role = roleDao.findById(id);
        return role;
    }

    @Override
    public List<Permission> findOtherPermission(int id) {

        return roleDao.findOtherPermission(id);
    }
    /**
     * 给角色添加资源权限
     * @param roleid
     * @return
     */
    @Override
    public void addPermissionToRole(int roleid, int[] ids) {
        for (int id : ids){
            roleDao.addPermissionToRole(roleid,id);
        }
    }
    /**
     * 删除角色
     * @param id
     * @return
     */
    @Override
    public void deleteRole(int id) {
            roleDao.deleteFromUserinfo(id);
            roleDao.deleteFromRp(id);
            roleDao.deleteRole(id);

    }
}
